package logic

import (
	"context"
	"home/homerpc/models/mysql"

	"home/homerpc/homerpc"
	"home/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *homerpc.HouseListRequest) (*homerpc.HouseListResponse, error) {
	// todo: add your logic here and delete this line

	var houses []mysql.House
	mysql.DB.Debug().Find(&houses)
	var houselist []*homerpc.HouseList
	for _, house := range houses {

		list := homerpc.HouseList{
			Address: house.Address,
			Price:   float32(house.Price),
			Status:  house.Status,
		}
		houselist = append(houselist, &list)
	}
	return &homerpc.HouseListResponse{
		List: houselist,
	}, nil
}
